package m.jclecai.com.utils;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Random;

import m.jclecai.com.bean.BallItem;

public class MakeRandomUtil {

    /***
     * @param n 取值范围
     * @param s 取值个数
     * @return 返回取值范围内多个数据，不包含0，10以下数据前+0 （不重复）
     * (0,10]
     * 数据样式，01，02，10，11
     */
    public static LinkedList<String> getBall(int n, int s) {
        LinkedList<String> ball = new LinkedList<String>();
        Random rand = new Random();
        int[] nums = new int[n];
        for (int i = 0; i < n + 1; i++) {
            int p = rand.nextInt(n);
            if (nums[p] != 0) {
                i--;
            } else {
                nums[p] = i;
            }
        }
        for (int i = 0; i < s; i++) {
            if (nums[i] < 10) {
                ball.add("0" + nums[i]);
            } else {
                ball.add("" + nums[i]);
            }
        }
        return ball;
    }


    /***
     * @param n 取值范围
     * @param s 取值个数
     * @return 返回取值范围内多个数据，不包含0，包含取值数（不重复）
     */
    public static LinkedList<String> getBall_non_zero(int n, int s) {
        LinkedList<String> ball = new LinkedList<String>();
        Random rand = new Random();
        int[] nums = new int[n];
        for (int i = 0; i < n + 1; i++) {
            int p = rand.nextInt(n);
            if (nums[p] != 0) {
                i--;
            } else {
                nums[p] = i;
            }
        }
        for (int i = 0; i < s; i++) {
            ball.add("" + nums[i]);
        }
        return ball;
    }


    public static int getBallPk10Two(Map<Integer, BallItem> map, Map<Integer, BallItem> map2) {
        int lotnum = 0;
        if (map == null || map2 == null) return lotnum;
        for (BallItem item : map.values()) {
            for (BallItem item2 : map2.values()) {
                if (!item.getBallNum().equals(item2.getBallNum())) lotnum++;
            }
        }
        return lotnum;
    }

    public static int getBallPk10Three(Map<Integer, BallItem> map, Map<Integer, BallItem> map2, Map<Integer, BallItem> map3) {
        int lotnum = 0;
        if (map == null || map2 == null || map3 == null) return lotnum;
        for (BallItem item : map.values()) {
            for (BallItem item2 : map2.values()) {
                for (BallItem item3 : map3.values()) {
                    if (!item.getBallNum().equals(item2.getBallNum()) &&
                            !item.getBallNum().equals(item3.getBallNum()) &&
                            !item2.getBallNum().equals(item3.getBallNum()))
                        lotnum++;
                }
            }
        }
        return lotnum;
    }

    public static int getBallPk10Four(Map<Integer, BallItem> map, Map<Integer, BallItem> map2, Map<Integer, BallItem> map3, Map<Integer, BallItem> map4) {
        int lotnum = 0;
        if (map == null || map2 == null || map3 == null || map4 == null) return lotnum;
        for (BallItem item : map.values()) {
            for (BallItem item2 : map2.values()) {
                for (BallItem item3 : map3.values()) {
                    for (BallItem item4 : map4.values()) {
                        if (!item.getBallNum().equals(item2.getBallNum()) &&
                                !item.getBallNum().equals(item3.getBallNum()) &&
                                !item.getBallNum().equals(item4.getBallNum()) &&
                                !item2.getBallNum().equals(item3.getBallNum()) &&
                                !item2.getBallNum().equals(item4.getBallNum()) &&
                                !item3.getBallNum().equals(item4.getBallNum())
                                )
                            lotnum++;
                    }
                }
            }
        }
        return lotnum;
    }

    /**
     * 球随机数
     *
     * @param range 取值范围
     * @return 返回取值范围内, 不包括取值数的单个数据 包含0
     * [0,range) ,特点，只返回一个值
     */
    public static LinkedList<String> getBall(int range) {
        LinkedList<String> balls = new LinkedList<String>();
        for (int i = 0; i < 1; i++) {
            int ball = (int) (Math.random() * range);
            if (i == 0) {
                balls.add(ball + "");
            } else {
                if (balls.get(i - 1) == ball + "") {
                    i--;
                } else {
                    balls.add(ball + "");
                }
            }
        }
        return balls;
    }

    /**
     * 球随机数
     *
     * @param n 取值范围
     * @param s 取值数量    s<n，否则会报数组越界
     * @return 返回取值范围内,不包含取值数的多个数据，包含0 (不重复)
     * [0,n) 不重复
     *  数据样式，0，1，2，3，4，
     */
    public static LinkedList<String> getWeiBall(int n, int s) {
        LinkedList<String> Balls = new LinkedList<String>();
        Random rand = new Random();
        int[] nums = new int[n];
        for (int i = 0; i < n; i++) {
            int p = rand.nextInt(n);
            if (nums[p] != 0) {
                i--;
            } else {
                nums[p] = i;
            }
        }
        for (int i = 0; i < s; i++) {
            Balls.add("" + nums[i]);
        }
        return Balls;
    }


    /**
     * @return
     * @category 双单大小随机数
     */
    public static LinkedList<Integer> getDBall() {
        LinkedList<Integer> balls = new LinkedList<Integer>();
        for (int i = 0; i < 1; i++) {
            int ball = (int) (Math.random() * 4);
            if (i == 0) {
                balls.add(ball);
            } else {
                if (balls.get(i - 1) == ball) {
                    i--;
                } else {
                    balls.add(ball);
                }
            }
        }
        return balls;
    }

    /**
     * @category 胜负彩随机数
     */
    public static int getZBall(int n, int s) {
        Random rand = new Random();
        int[] nums = new int[n];
        for (int i = 0; i < n + 1; i++) {
            int p = rand.nextInt(n);
            if (nums[p] != 0) {
                i--;
            } else {
                nums[p] = i;
            }
        }
        return nums[0];
    }

    /**
     * @category 任选九随机数
     */
    public static LinkedList<Integer> getRBall(int n, int s) {
        LinkedList<Integer> redBall = new LinkedList<Integer>();
        Random rand = new Random();
        int[] nums = new int[n];
        for (int i = 0; i < n + 1; i++) {
            int p = rand.nextInt(n);
            if (nums[p] != 0) {
                i--;
            } else {
                nums[p] = i;
            }
        }
        for (int i = 0; i < s; i++) {
            if (nums[i] < 10) {
                redBall.add(nums[i]);
            } else {
                redBall.add(nums[i]);
            }
        }
        return redBall;
    }



    /**
     * @category 红球随机数
     * @return
     */
    public static LinkedList<String> getRedBall(int n, int s) {
        LinkedList<String> redBall = new LinkedList<String>();
        Random rand = new Random();
        int[] nums = new int[n];
        for (int i = 0; i < n + 1; i++) {
            int p = rand.nextInt(n);
            if (nums[p] != 0) {
                i--;
            } else {
                nums[p] = i;
            }
        }
        for (int i = 0; i < s; i++) {
            if (nums[i] < 10) {
                redBall.add("0" + nums[i]);
            } else {
                redBall.add("" + nums[i]);
            }
        }
        return redBall;
    }

    /**
     * @category 蓝球随机数
     * @return
     */
    public static LinkedList<String> getBuleBall(int n, int s) {
        LinkedList<String> buleBall = new LinkedList<String>();
        Random rand = new Random();
        int[] nums = new int[n];
        for (int i = 0; i < n + 1; i++) {
            int p = rand.nextInt(n);
            if (nums[p] != 0) {
                i--;
            } else {
                nums[p] = i;
            }
        }
        for (int i = 0; i < s; i++) {
            if (nums[i] < 10) {
                buleBall.add("0" + nums[i]);
            } else {
                buleBall.add("" + nums[i]);
            }
        }

        return buleBall;
    }

    /**
     * @category 球随机数
     * @return
     */
    public static LinkedList<String> getBall() {
        LinkedList<String> balls = new LinkedList<String>();
        for (int i = 0; i < 1; i++) {
            int ball = (int) (Math.random() * 10);
            if (i == 0) {
                balls.add(ball + "");
            } else {
                if (balls.get(i - 1) == ball + "") {
                    i--;
                } else {
                    balls.add(ball + "");
                }
            }
        }
        return balls;
    }

    /***
     * 产生随机数，可能重复；
     * @param range  随机数的范围；
     * @param size 随机数的个数
     * @return 随机数的集合
     * [0,range)
     */
    public static List<String> getRandomWidthRepeat(int range, int size){

        ArrayList<String> arrayList = new ArrayList<>();

        for (int i = 0; i < size; i++) {

            arrayList.add ((int) (Math.random() * range)+"");

        }
        return arrayList;
    }

}
